package application;

import java.net.URL;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import util.CentralControl;
import javafx.scene.Scene;
import javafx.scene.Parent;

public class Main extends Application {
	@Override
	public void start(Stage primaryStage) {
		CentralControl s = new CentralControl();
		try {
			// Read file fxml and draw interface.
			URL location = getClass().getResource("/application/Main.fxml");
			FXMLLoader fxmlLoader = new FXMLLoader();
			fxmlLoader.setLocation(location);
			fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
			Parent root = (Parent) fxmlLoader.load(location.openStream());
			MainController mainCtrl = (MainController) fxmlLoader.getController(); // 获取FXMLoader中对应的controller
			mainCtrl.setCenCtrl(s);
			//Parent root = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
			root.setId("root");
			primaryStage.setTitle("食品安全");
			Scene scene = new Scene(root);
			primaryStage.setScene(scene);
			primaryStage.setTitle("网络采集EMA系统");
			primaryStage.setResizable(false);
			primaryStage.setOnShowing(new EventHandler<WindowEvent>() { //监听窗口打开
		        @Override
		        public void handle(WindowEvent event) {    
		            mainCtrl.setcursor();
		        }
		    });
			primaryStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		launch(args);
	}
}